package com.example.demo.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.Admin;

/**
 * 用户页面跳转
 */
@CrossOrigin(allowCredentials = "true", origins = "*", maxAge = 3600, methods = { RequestMethod.GET, RequestMethod.POST,
		RequestMethod.PUT,
		RequestMethod.OPTIONS }, allowedHeaders = { "x-requested-with", "accept", "authorization", "content-type" })
@Controller
public class UserController {

    /**
 	 * 个人中心，需认证可访问
 	 */
    @RequestMapping("/user/index")
    public String add(HttpServletRequest request){
        Admin bean = (Admin) SecurityUtils.getSubject().getPrincipal();
        request.setAttribute("userName", bean.getUsername());
        return "/user/index";
    }

    /**
 	 * 会员中心，需认证且角色为vip可访问
 	 */
    @RequestMapping("/vip/index")
    public String update(){
        return "/vip/index";
    }
}
